--
-- Author: shunguo.chen
-- Date: 2018-06-01 14:41:26
--
-- IconSimpleRender 对 Res.BaseIconSimple 的解析，IconRender的精简版
--

local ClassRef = app.mvc.createRenderClass(...)

-- data = Item/Equip/Mount/Fame/Tool/Daibi
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.BaseIconSimple))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)

    self:setContentSize(self._ui.Panel:getContentSize())
    self:refresh()
end

function ClassRef:setNewScale(len)
    self:setAnchorPoint(cc.p(0.5, 0.5))
    local size = self:getContentSize()
    local scale = len / size.height
    self:setScale(scale)
end

function ClassRef:refresh()
    if self._data then
        local data = self._data

        self:setIcon(data:getIcon())
        self:setIconKuang(data:getIconBg())
    end
end

function ClassRef:setIconKuang(res)
    self._ui.grade:loadTexture(res)
end

function ClassRef:setIcon(res)
    self._ui.icon:setVisible(true)
    self._ui.icon:loadTexture(res)
end

return ClassRef
